﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SRM;
using SRM.DataObjects;
using System.Data;

public partial class UserControls_AdditionalPersonalParticularsUserControl : System.Web.UI.UserControl, SRM.IUserInput
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            //Bind combo boxes
            Help.BindSapCodeToComboBox(race_combobox, SRM_Code.GetRace("1"));
            Help.BindSapCodeToComboBox(maritalstatus_radcombobox, SRM_Code.GetMaritalStatus("1"));
            Help.BindSapCodeToComboBox(dialect_radcombobox, SRM_Code.GetDialect("1"));
            Help.BindSapCodeToComboBox(religion_radcombobox, SRM_Code.GetReligion("1"));

            // Get AdditionPersonalParticulars()
            if (Page is IApplicantForm)
            {
                string applicantKey = string.Empty;
                applicantKey = ((IApplicantForm)Page).ApplicantKey;
                DataTable dt = SRM_Applicant.GetAdditionPersonalParticulars(applicantKey);

                if ((dt != null) && (dt.Rows.Count > 0))
                {
                    System.Data.DataRow row = dt.Rows[0];
                    dateofbirth_datepicker.SelectedDate = row.Field<DateTime?>("DateOfBirth");
                    maritalstatussince_datepicker.SelectedDate = row.Field<DateTime?>("MarriedSince");
                    noofchildren_numerictextbox.Value = row.Field<byte?>("NoOfChildren");
                    //race_combobox.SelectedValue = row.Field<string>("Race");
                    //maritalstatus_radcombobox.SelectedValue = row.Field<string>("MaritalStatus");
                    //gender_combobox.SelectedValue = row.Field<string>("Gender");
                    //dialect_radcombobox.SelectedValue = row.Field<string>("Dialect");
                    //religion_radcombobox.SelectedValue = row.Field<string>("Religion");
                    Help.SetComboBoxSelectedValue(race_combobox, row.Field<string>("Race"));
                    Help.SetComboBoxSelectedValue(maritalstatus_radcombobox, row.Field<string>("MaritalStatus"));
                    Help.SetComboBoxSelectedValue(gender_combobox, row.Field<string>("Gender"));
                    Help.SetComboBoxSelectedValue(dialect_radcombobox, row.Field<string>("Dialect"));
                    Help.SetComboBoxSelectedValue(religion_radcombobox, row.Field<string>("Religion"));

                    if (maritalstatus_radcombobox.SelectedValue == "1")
                    {
                        Label_Since.Visible = true;
                        maritalstatussince_datepicker.Visible = true;
                        maritalstatussince_datepicker_hint.Visible = true;
                    }
                    else
                    {
                        Label_Since.Visible = false;
                        maritalstatussince_datepicker.Visible = false;
                        maritalstatussince_datepicker_hint.Visible = false;
                    }
                }
            }
        }
    }

    public void SaveUserInput()
    {
        string applicantKey = string.Empty;

        if (Page is IApplicantForm)
        {
            applicantKey = ((IApplicantForm)Page).ApplicantKey;
            SRM_Applicant.UpdateAdditionPersonalParticulars(applicantKey,
                dateofbirth_datepicker.SelectedDate,
                race_combobox.SelectedValue,
                maritalstatus_radcombobox.SelectedValue,
                maritalstatussince_datepicker.SelectedDate,
                gender_combobox.SelectedValue,
                noofchildren_numerictextbox.Text,
                dialect_radcombobox.SelectedValue,
                religion_radcombobox.SelectedValue);
        }
    }

    protected void maritalstatus_radcombobox_SelectedIndexChanged(object o, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
    {
        if (maritalstatus_radcombobox.SelectedValue == "1")
        {
            Label_Since.Visible = true;
            maritalstatussince_datepicker.Visible = true;
            maritalstatussince_datepicker_hint.Visible = true;
        }
        else
        {
            Label_Since.Visible = false;
            maritalstatussince_datepicker.Visible = false;
            maritalstatussince_datepicker_hint.Visible = false;
        }
    }
}